package com.acwebsitedesign.uRateDrugs.domain;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { "/spring-service.xml" } )
public class ReviewServiceTestIntegration {
	
	@Autowired
	DrugService drugService;
	
	@Autowired
	ReviewService reviewService;
	
	@Test
	public void getReviewsForADrug(){
		
		Drug drug = new Drug();
		String name = "Test Drug";
		drug.setName(name);
		drug.setClassOfDrug(name);
		drug.setWhyIsThisMedicationPrescribed(name);
		drug.setOtherBrands(name);
		drug.setSideEffects(name);
		drug.setWarnings(name);
		drug.setTreats(name);
		drugService.saveDrug(drug);
		
		List <Drug> drugList = drugService.getDrugByName(name);
		Drug drug2 = drugList.get(0);
		int drugId = drug2.getId();
		
		Review review = new Review();
		String sample = "sample";
		review.setPositiveReview(true);
		review.setRating(4);
		review.setReasonForTaking(sample);
		review.setReviewText(sample);
		review.setUser_id(12);
		review.setDrug_id(drugId);
		reviewService.saveReview(review);

	}
	
	@Test
	public void getAllReviewsFromAUser(){
		int userId = 12;
		List <Review> reviewList = reviewService.getAllReviewsFromAUser(userId);
		int size = reviewList.size();
		System.out.println("Number of reviews: " + size);
	}
	
	@Test
	public void saveReview(){	

		Drug drug = new Drug();
		String name = "Test Drug";
		drug.setName(name);
		drug.setClassOfDrug(name);
		drug.setWhyIsThisMedicationPrescribed(name);
		drug.setOtherBrands(name);
		drug.setSideEffects(name);
		drug.setWarnings(name);
		drug.setTreats(name);
		drugService.saveDrug(drug);
		
		List <Drug> drugList = drugService.getDrugByName(name);
		Drug drug2 = drugList.get(0);
		int drugId = drug2.getId();
		
		Review review = new Review();
		String sample = "sample";
		review.setPositiveReview(true);
		review.setRating(4);
		review.setReasonForTaking(sample);
		review.setReviewText(sample);
		review.setUser_id(12);
		review.setDrug_id(drugId);
		reviewService.saveReview(review);
		
	}
	
	@Test
	public void removeReviews(){
		int id = 12;
		List<Review> reviewList = reviewService.getAllReviewsFromAUser(id);
		for (Review review : reviewList){
			int reviewId = review.getId();
			reviewService.removeReview(reviewId);
		}
		
	}
	
	@Test
	public void removeAllReviewsForAUser(){
		int id = 12;
		reviewService.removeAllReviewsForAUser(id);
	}
	
}
